package com.me.test.config;

import com.me.test.enums.BaseEnum;
import com.me.test.enums.ErrorCodeEnum;

/**
 * 业务异常.
 */
public class BusinessException extends RuntimeException {

	private static final long serialVersionUID = -5590937297668648146L;
	/**
	 * 异常码
	 */
	protected String code;

	private BusinessException(String code, String message) {
		super(message);
		this.code = code;
	}

	private BusinessException(BaseEnum codeEnum, Object... args) {
		super(String.format(codeEnum.getMsg(), args));
		this.code = codeEnum.getCode();
	}

	public String getCode() {
		return code;
	}

	public static BusinessException build(String code, String message) {
		return new BusinessException(code, message);
	}

	public static BusinessException build(BaseEnum errorEnum, Object... args) {
		return new BusinessException(errorEnum, args);
	}

}
